﻿namespace OP10.ViewModels
{
    public class ST01CyManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST01CyManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
        }



        private void InitParam()
        {
            //感应器参数初始化赋值

            IsCheck01 = InductorParam_Global.aByPass[0];
            IsCheck02 = InductorParam_Global.aByPass[1];
            IsCheck03 = InductorParam_Global.aByPass[2];
            IsCheck04 = InductorParam_Global.aByPass[3];
            IsCheck05 = InductorParam_Global.aByPass[4];


            CylinderDelay.DelayTime01 = ST01CheckUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime02 = ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime03 = ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime04 = ST01CheckCarryCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime05 = ST01CheckSpinCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime06 = ST01CheckClampCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime07 = ST01LoadUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime08 = ST01LoadSpinCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime09 = ST01LoadJackCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime10 = ST01RectifyCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime11 = ST01BlowAirCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime12 = ST01CheckUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime13 = ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime14 = ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime15 = ST01CheckCarryCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime16 = ST01CheckSpinCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime17 = ST01CheckClampCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime18 = ST01LoadUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime19 = ST01LoadSpinCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime20 = ST01LoadJackCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime21 = ST01RectifyCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime22 = ST01BlowAirCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime23 = InductorParam_Global.aDelay[0];
            CylinderDelay.DelayTime24 = InductorParam_Global.aDelay[1];
            CylinderDelay.DelayTime25 = InductorParam_Global.aDelay[2];
            CylinderDelay.DelayTime26 = InductorParam_Global.aDelay[3];
            CylinderDelay.DelayTime27 = InductorParam_Global.aDelay[4];

            checkModel.IsQGOriginCheck01 = ST01CheckUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck02 = ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck03 = ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck04 = ST01CheckCarryCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck05 = ST01CheckSpinCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck06 = ST01CheckClampCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck07 = ST01LoadUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck08 = ST01LoadSpinCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck09 = ST01LoadJackCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck10 = ST01RectifyCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck11 = ST01RectifyCy.cylinderPCToPLC_Global.bOrgSenByPass;


            checkModel.IsQGWorkCheck01 = ST01CheckUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck02 = ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck03 = ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck04 = ST01CheckCarryCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck05 = ST01CheckSpinCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck06 = ST01CheckClampCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck07 = ST01LoadUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck08 = ST01LoadSpinCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck09 = ST01LoadJackCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck10 = ST01RectifyCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck11 = ST01RectifyCy.cylinderPCToPLC_Global.bWorkSenByPass;
        }
        #region 事件


        private DelegateCommand _GoBackCommand;
        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));
        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST01");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST01View, param);
        }
        /// <summary>
        /// 气缸感应器屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderPinBiCommand;
        public DelegateCommand<string> CylinderPinBiCommand =>
            _CylinderPinBiCommand ?? (_CylinderPinBiCommand = new DelegateCommand<string>(ExecuteCylinderPinBiCommand));
        void ExecuteCylinderPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST1极性检测上下原点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测搬运夹爪原点":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测旋转夹爪原点":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测搬运原点":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测旋转原点":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测夹持原点":
                    ST01CheckClampCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1上料上下原点":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1上料旋转原点":
                    ST01LoadSpinCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1上料顶升原点":
                    ST01LoadJackCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1矫正夹爪原点":
                    ST01RectifyCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1直振吹气原点":
                    ST01BlowAirCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST1极性检测上下动点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测搬运夹爪动点":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测旋转夹爪动点":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测搬运动点":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测旋转动点":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测夹持动点":
                    ST01CheckClampCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1上料上下动点":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1上料旋转动点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1上料顶升动点":
                    ST01LoadJackCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1矫正夹爪动点":
                    ST01RectifyCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1直振吹气动点":
                    ST01BlowAirCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST1极性检测来料感应":
                    InductorParam_Global.aByPass[0] = true;
                    break;
                case "ST1极性检测流走感应":
                    InductorParam_Global.aByPass[1] = true;
                    break;
                case "ST1上料来料感应":
                    InductorParam_Global.aByPass[2] = true;
                    break;
                case "ST1上料直振满料感应":
                    InductorParam_Global.aByPass[3] = true;
                    break;
                case "ST1圆振缺料检测":
                    InductorParam_Global.aByPass[4] = true;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 气缸感应器解除屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderUnPinBiCommand;
        public DelegateCommand<string> CylinderUnPinBiCommand =>
            _CylinderUnPinBiCommand ?? (_CylinderUnPinBiCommand = new DelegateCommand<string>(ExecuteCylinderUnPinBiCommand));

        void ExecuteCylinderUnPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST1极性检测上下原点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测搬运夹爪原点":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测旋转夹爪原点":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测搬运原点":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测旋转原点":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测夹持原点":
                    ST01CheckClampCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1上料上下原点":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1上料旋转原点":
                    ST01LoadSpinCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1上料顶升原点":
                    ST01LoadJackCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1矫正夹爪原点":
                    ST01RectifyCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1直振吹气原点":
                    ST01BlowAirCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST1极性检测上下动点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测搬运夹爪动点":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测旋转夹爪动点":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测搬运动点":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测旋转动点":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测夹持动点":
                    ST01CheckClampCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1上料上下动点":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1上料旋转动点":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1上料顶升动点":
                    ST01LoadJackCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1矫正夹爪动点":
                    ST01RectifyCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1直振吹气动点":
                    ST01BlowAirCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST1极性检测来料感应":
                    InductorParam_Global.aByPass[0] = false;
                    break;
                case "ST1极性检测流走感应":
                    InductorParam_Global.aByPass[1] = false;
                    break;
                case "ST1上料来料感应":
                    InductorParam_Global.aByPass[2] = false;
                    break;
                case "ST1上料直振满料感应":
                    InductorParam_Global.aByPass[3] = false;
                    break;
                case "ST1圆振缺料检测":
                    InductorParam_Global.aByPass[4] = false;
                    break;
                default:
                    break;
            }
        }
        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "DelayTime01":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime01;
                    break;
                case "DelayTime02":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime02;
                    break;
                case "DelayTime03":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime03;
                    break;
                case "DelayTime04":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime04;
                    break;
                case "DelayTime05":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime05;
                    break;
                case "DelayTime06":
                    ST01CheckClampCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime06;
                    break;
                case "DelayTime07":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime07;
                    break;
                case "DelayTime08":
                    ST01LoadSpinCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime08;
                    break;
                case "DelayTime09":
                    ST01LoadJackCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime09;
                    break;
                case "DelayTime10":
                    ST01RectifyCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime10;
                    break;
                case "DelayTime11":
                    ST01BlowAirCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime11;
                    break;
                case "DelayTime12":
                    ST01CheckUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime12;
                    break;
                case "DelayTime13":
                    ST01CheckCarryJiaZhuaCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime13;
                    break;
                case "DelayTime14":
                    ST01CheckSpinJiaZhuaCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime14;
                    break;
                case "DelayTime15":
                    ST01CheckCarryCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime15;
                    break;
                case "DelayTime16":
                    ST01CheckSpinCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime16;
                    break;
                case "DelayTime17":
                    ST01CheckClampCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime17;
                    break;
                case "DelayTime18":
                    ST01LoadUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime18;
                    break;
                case "DelayTime19":
                    ST01LoadSpinCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime19;
                    break;
                case "DelayTime20":
                    ST01LoadJackCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime20;
                    break;
                case "DelayTime21":
                    ST01RectifyCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime21;
                    break;
                case "DelayTime22":
                    ST01BlowAirCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime22;
                    break;
                case "DelayTime23":
                    InductorParam_Global.aDelay[0] = CylinderDelay.DelayTime23;
                    break;
                case "DelayTime24":
                    InductorParam_Global.aDelay[1] = CylinderDelay.DelayTime24;
                    break;
                case "DelayTime25":
                    InductorParam_Global.aDelay[2] = CylinderDelay.DelayTime25;
                    break;
                case "DelayTime26":
                    InductorParam_Global.aDelay[3] = CylinderDelay.DelayTime26;
                    break;
                case "DelayTime27":
                    InductorParam_Global.aDelay[4] = CylinderDelay.DelayTime27;
                    break;
                default:
                    break;
            }
        }
        #endregion
        #region 属性  

        private CylinderDelayModel _cylinderDelay;
        public CylinderDelayModel CylinderDelay
        {
            get { return _cylinderDelay ?? (_cylinderDelay = new CylinderDelayModel()); }
            set { SetProperty(ref _cylinderDelay, value); }
        }
        private bool _IsCheck01;
        public bool IsCheck01
        {
            get { return _IsCheck01; }
            set { SetProperty(ref _IsCheck01, value); }
        }
        private bool _IsCheck02;
        public bool IsCheck02
        {
            get { return _IsCheck02; }
            set { SetProperty(ref _IsCheck02, value); }
        }
        private bool _IsCheck03;
        public bool IsCheck03
        {
            get { return _IsCheck03; }
            set { SetProperty(ref _IsCheck03, value); }
        }
        private bool _IsCheck04;
        public bool IsCheck04
        {
            get { return _IsCheck04; }
            set { SetProperty(ref _IsCheck04, value); }
        }
        private bool _IsCheck05;
        public bool IsCheck05
        {
            get { return _IsCheck05; }
            set { SetProperty(ref _IsCheck05, value); }
        }
        private CylinderSensorCheckModel _checkModel;
        public CylinderSensorCheckModel checkModel
        {
            get { return _checkModel??(_checkModel=new CylinderSensorCheckModel()); }
            set { SetProperty(ref _checkModel, value); }
        }
        #endregion
    }
}
